package com.springboot.show_web.controller;

import com.springboot.show_web.exception.UserNotExistException;
import com.springboot.show_web.vo.user;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * Created by yaosheng on 2019/11/2.
 */
@Slf4j
@Controller
public class HelloController {

//    @RequestMapping({"/","index.html"})
//    public String index(){
//        return "index";
//    }

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam("user") String user) {
        if (user.equals ("aaa")) {
            throw new UserNotExistException ();
        }
        return "Hello World !";
    }

    @RequestMapping("/success")
    public String success(Map<String, Object> map) {
        map.put ("hello", "<h1>你好</h1>");
        map.put ("users", Arrays.asList ("姚圣", "李岫岩", "付洁琳"));
        return "success";
    }

    @GetMapping("/jackson")
    public user jackson() throws Exception{
        user user1 = user.builder()
                .name("Great")
                .age(24)
                .address("陕西省渭南市")
                .registerTime(new Date())
                .build();
        return user1;
    }
}